package zhu.areas.recruit.action;

import java.util.Date;
import java.util.List;

import org.apache.struts2.ServletActionContext;

import zhu.areas.dic.data.RecruitAppStatue;
import zhu.areas.recruit.data.RecruitApply;
import zhu.areas.recruit.data.RecruitPlanComm;
import zhu.areas.recruit.service.IRecruitYuService;
import zhu.common.data.Pager;
import zhu.common.service.IDicService;

import com.opensymphony.xwork2.ActionSupport;
//企业招聘中提交招聘计划、招聘计划审核、发布招聘计划子模块
public class RecruitYuAction extends ActionSupport {

	private List<RecruitApply> recruitList;
	private List<RecruitAppStatue> statueList;
	private List<RecruitPlanComm> commList;
	private RecruitApply recruitApply;
	private RecruitAppStatue recruitAppStatue;
	private RecruitPlanComm recruitPlanComm;

	private IRecruitYuService recruitYuService;
	private IDicService dicService;
	
	private Integer empoymentID;
	private Integer applierID;
	private String applierName;
	private Date appTime;
	private Integer empAuditStatue;
	private Integer auditorID;
	private String auditorName;
	private Date auditTime;
	private String position;
	private String postName;
	private String workPlace;
	private Integer employNum;
	private String postDuty;
	private String postRequire;
	private Float postSalary;
	private String empCompany;
	private String belong;
	private String properties;
	private String comScale;
	private String companySite;
	private Date pubTime;
	private String degree;
	private String experience;
	private String phone;

	private Integer comID;
	private Integer AppFormID;
	private Integer commOperatorID;
	private String commOperatorName;
	private Date commTime;
	private String comMes;
	
	private Pager pager;
	private String currentPage;
	private String pageMethod;
	private Integer pageSize = 7;// 每页显示的记录数目
	
	public String index() {
		return SUCCESS;
	}
	/*
	 * 提交招聘计划
	 */
	public String SubmitRecruitPlan() {
		convertPageToRecruit();
		// recruitApply.setStatue(recruitAppStatueService.findByID(StatueID));//返回值是recruitAppStatue类
		try {
			if (recruitYuService.addRecruitApply(recruitApply)) {
				System.out.println("申请进入审核中……！");
			}
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ERROR;
	}

	/*
	 * 审核招聘计划(列出未审核计划)
	 */
	public String AuditRecruitPlan() {
		// Integer statueID = recruitApply.getStatue().setStatueID(1);
		Integer statueID = 1;
		this.pager = this.recruitYuService.findPageRecruit(statueID, pageSize,
				currentPage, pageMethod);
		if (pager == null)
			System.out.println("pager为空!");
		this.recruitList = this.pager.getList();
		this.setCurrentPage(String.valueOf(this.pager.getCurrentPage()));
		return SUCCESS;
	}

	/*
	 * 审核招聘计划(待审核详细)
	 */
	public String AuditPlan() {
		
		//本处使用session传值不太合理，以后应该使用其他的传值方式代替
		ServletActionContext.getRequest().getSession().setAttribute("empoymentID", empoymentID);
		System.out.println(empoymentID);
		//statueList = recruitAppStatueService.getAllStatue();
		statueList = (List<RecruitAppStatue>) dicService.getAllValueAndId("RecruitAppStatue");
		recruitApply = recruitYuService.getByEmpoymentID(empoymentID);
		convertRecruitToPage(recruitApply);
		return SUCCESS;
	}

	/*
	 * 审核招聘计划(审核提交)
	 */
	public String AuditSubmit() {
		Integer id=(Integer) ServletActionContext.getRequest().getSession().getAttribute("empoymentID");
		System.out.println(id);
		recruitApply = recruitYuService.getByEmpoymentID(id);
		System.out.println(recruitApply.getApplierName());
		auditorID = (Integer) ServletActionContext.getRequest().getSession()
				.getAttribute("userID");
		auditorName = ServletActionContext.getRequest().getSession()
				.getAttribute("userName").toString();
		recruitApply.setAuditorID(auditorID);
		recruitApply.setAuditorName(auditorName);
		recruitApply.setAuditTime(new Date());
		System.out.println(this.getEmpAuditStatue());
		System.out.println(auditorName);
		//recruitAppStatue = recruitAppStatueService.getByEmpAuditStatue(this.getEmpAuditStatue());
		recruitAppStatue =(RecruitAppStatue) dicService.getValueById("RecruitAppStatue", "statueID", this.getEmpAuditStatue());
		
		recruitApply.setStatue(recruitAppStatue);
		System.out.println(recruitApply.getStatue().getEmpAuditStatue());
		try {
			if (recruitYuService.updateRecruit(recruitApply)) {
				System.out.println("审核完毕！");
				return SUCCESS;
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ERROR;
	}

	/*
	 * 发布招聘计划
	 */
	public String ReleaseRecruitPlan() {
		Integer statueID = 3;		
		this.pager = this.recruitYuService.findPageRecruit(statueID, pageSize,
				currentPage, pageMethod);
		if (pager == null)
			System.out.println("pager为空!");
		this.recruitList = this.pager.getList();
		this.setCurrentPage(String.valueOf(this.pager.getCurrentPage()));
		return SUCCESS;
	}	

	/*
	 * 点评招聘计划（详细）
	 */
	public String ReleasePlan() {
		ServletActionContext.getRequest().getSession().setAttribute("empoymentID", empoymentID);
		System.out.println(empoymentID);
		recruitApply = recruitYuService.getByEmpoymentID(empoymentID);
		convertRecruitToPage(recruitApply);
		return SUCCESS;
	}

	/*
	 * 点评招聘计划（点评提交）
	 */
	public String RecruitCommSubmit() {
		recruitPlanComm = new RecruitPlanComm();
		recruitApply=new RecruitApply();

		commOperatorID = (Integer) ServletActionContext.getRequest()
				.getSession().getAttribute("userID");
		commOperatorName = ServletActionContext.getRequest().getSession()
				.getAttribute("userName").toString();
		System.out.println(commOperatorID);
		System.out.println(commOperatorName);
		recruitPlanComm.setCommOperatorID(commOperatorID);
		System.out.println(recruitPlanComm.getCommOperatorID());
		recruitPlanComm.setCommOperatorName(commOperatorName);
		recruitPlanComm.setCommTime(new Date());
		recruitPlanComm.setComMes(this.getComMes());
		
		Integer id=(Integer) ServletActionContext.getRequest().getSession().getAttribute("empoymentID");
		System.out.println(id);
		recruitApply = recruitYuService.getByEmpoymentID(id);
		System.out.println(recruitApply.getEmpCompany());
		recruitPlanComm.setRecruitApply(recruitApply);	
		try {
			System.out.println(recruitPlanComm.getCommOperatorID());
			
			if (recruitYuService.addRecruitPlanComm(recruitPlanComm)){
				System.out.println("点评完毕！");
				return SUCCESS;
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ERROR;

	}

	// 将页面中的属性转化成数据库中RecruitApply对象
	private void convertPageToRecruit() {
		recruitApply = new RecruitApply();

		applierID = (Integer) ServletActionContext.getRequest().getSession()
				.getAttribute("userID");
		applierName = ServletActionContext.getRequest().getSession()
				.getAttribute("userName").toString();
		System.out.println(applierID);
		System.out.println(applierName);
		
		recruitApply.setStatue(new RecruitAppStatue(1));
		recruitApply.setApplierID(applierID);
		recruitApply.setApplierName(applierName);
		recruitApply.setAppTime(new Date());
		
		recruitApply.setEmpCompany(this.getEmpCompany());
		recruitApply.setBelong(this.getBelong());
		recruitApply.setProperties(this.getProperties());
		recruitApply.setComScale(this.getComScale());
		recruitApply.setCompanySite(this.getCompanySite());

		recruitApply.setPostName(this.getPostName());
		recruitApply.setWorkPlace(this.getWorkPlace());
		recruitApply.setEmployNum(this.getEmployNum());
		recruitApply.setPostDuty(this.getPostDuty());
		recruitApply.setPostRequire(this.getPostRequire());
		recruitApply.setPostSalary(this.getPostSalary());

		recruitApply.setDegree(this.getDegree());
		recruitApply.setExperience(this.getExperience());
		recruitApply.setPhone(this.getPhone());

		recruitApply.setPosition(this.getPosition());
	}

	// 将从数据库获取地RecruitApply对象转化成页面中的属性
	private void convertRecruitToPage(RecruitApply recruitApply) {
		this.setEmpoymentID(recruitApply.getEmpoymentID());
		this.setApplierID(recruitApply.getApplierID());
		this.setApplierName(recruitApply.getApplierName());
		this.setAppTime(recruitApply.getAppTime());
		this.setEmpAuditStatue(recruitApply.getStatue().getStatueID());
		this.setAuditorID(recruitApply.getAuditorID());
		this.setAuditorName(recruitApply.getApplierName());
		this.setAuditTime(recruitApply.getAppTime());
		this.setPosition(recruitApply.getPosition());
		this.setPostName(recruitApply.getPostName());
		this.setWorkPlace(recruitApply.getWorkPlace());
		this.setEmployNum(recruitApply.getEmployNum());
		this.setPostDuty(recruitApply.getPostDuty());
		this.setPostRequire(recruitApply.getPostRequire());
		this.setPostSalary(recruitApply.getPostSalary());
		this.setEmpCompany(recruitApply.getEmpCompany());
		this.setBelong(recruitApply.getBelong());
		this.setProperties(recruitApply.getProperties());
		this.setComScale(recruitApply.getComScale());
		this.setCompanySite(recruitApply.getCompanySite());
		this.setPubTime(recruitApply.getPubTime());
		this.setDegree(recruitApply.getDegree());
		this.setExperience(recruitApply.getExperience());
		this.setPhone(recruitApply.getPhone());
	}

	public Pager getPager() {
		return pager;
	}

	public void setPager(Pager pager) {
		this.pager = pager;
	}

	public String getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(String currentPage) {
		this.currentPage = currentPage;
	}

	public String getPageMethod() {
		return pageMethod;
	}

	public void setPageMethod(String pageMethod) {
		this.pageMethod = pageMethod;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	
	public List<RecruitApply> getRecruitList() {
		return recruitList;
	}

	public void setRecruitList(List<RecruitApply> recruitList) {
		this.recruitList = recruitList;
	}

	public List<RecruitAppStatue> getStatueList() {
		return statueList;
	}

	public void setStatueList(List<RecruitAppStatue> statueList) {
		this.statueList = statueList;
	}

	public RecruitApply getRecruitApply() {
		return recruitApply;
	}

	public void setRecruitApply(RecruitApply recruitApply) {
		this.recruitApply = recruitApply;
	}

	public IRecruitYuService getRecruitYuService() {
		return recruitYuService;
	}

	public void setRecruitYuService(IRecruitYuService recruitYuService) {
		this.recruitYuService = recruitYuService;
	}

	public RecruitAppStatue getRecruitAppStatue() {
		return recruitAppStatue;
	}

	public void setRecruitAppStatue(RecruitAppStatue recruitAppStatue) {
		this.recruitAppStatue = recruitAppStatue;
	}

	public IDicService getDicService() {
		return dicService;
	}

	public void setDicService(IDicService dicService) {
		this.dicService = dicService;
	}

	public List<RecruitPlanComm> getCommList() {
		return commList;
	}

	public void setCommList(List<RecruitPlanComm> commList) {
		this.commList = commList;
	}

	public RecruitPlanComm getRecruitPlanComm() {
		return recruitPlanComm;
	}

	public void setRecruitPlanComm(RecruitPlanComm recruitPlanComm) {
		this.recruitPlanComm = recruitPlanComm;
	}
	
	
/*************************招聘申请表*********************************/

	public Integer getEmpoymentID() {
		return empoymentID;
	}

	public void setEmpoymentID(Integer empoymentID) {
		this.empoymentID = empoymentID;
	}

	public Integer getApplierID() {
		return applierID;
	}

	public void setApplierID(Integer applierID) {
		this.applierID = applierID;
	}

	public String getApplierName() {
		return applierName;
	}

	public void setApplierName(String applierName) {
		this.applierName = applierName;
	}

	public Date getAppTime() {
		return appTime;
	}

	public void setAppTime(Date appTime) {
		this.appTime = appTime;
	}

	public Integer getEmpAuditStatue() {
		return empAuditStatue;
	}

	public void setEmpAuditStatue(Integer empAuditStatue) {
		this.empAuditStatue = empAuditStatue;
	}

	public Integer getAuditorID() {
		return auditorID;
	}

	public void setAuditorID(Integer auditorID) {
		this.auditorID = auditorID;
	}

	public String getAuditorName() {
		return auditorName;
	}

	public void setAuditorName(String auditorName) {
		this.auditorName = auditorName;
	}

	public Date getAuditTime() {
		return auditTime;
	}

	public void setAuditTime(Date auditTime) {
		this.auditTime = auditTime;
	}

	public String getPosition() {
		return position;
	}

	public void setPosition(String position) {
		this.position = position;
	}

	public String getPostName() {
		return postName;
	}

	public void setPostName(String postName) {
		this.postName = postName;
	}

	public String getWorkPlace() {
		return workPlace;
	}

	public void setWorkPlace(String workPlace) {
		this.workPlace = workPlace;
	}

	public Integer getEmployNum() {
		return employNum;
	}

	public void setEmployNum(Integer employNum) {
		this.employNum = employNum;
	}

	public String getPostDuty() {
		return postDuty;
	}

	public void setPostDuty(String postDuty) {
		this.postDuty = postDuty;
	}

	public String getPostRequire() {
		return postRequire;
	}

	public void setPostRequire(String postRequire) {
		this.postRequire = postRequire;
	}

	public Float getPostSalary() {
		return postSalary;
	}

	public void setPostSalary(Float postSalary) {
		this.postSalary = postSalary;
	}

	public String getEmpCompany() {
		return empCompany;
	}

	public void setEmpCompany(String empCompany) {
		this.empCompany = empCompany;
	}

	public String getBelong() {
		return belong;
	}

	public void setBelong(String belong) {
		this.belong = belong;
	}

	public String getProperties() {
		return properties;
	}

	public void setProperties(String properties) {
		this.properties = properties;
	}

	public String getComScale() {
		return comScale;
	}

	public void setComScale(String comScale) {
		this.comScale = comScale;
	}

	public String getCompanySite() {
		return companySite;
	}

	public void setCompanySite(String companySite) {
		this.companySite = companySite;
	}

	public Date getPubTime() {
		return pubTime;
	}

	public void setPubTime(Date pubTime) {
		this.pubTime = pubTime;
	}

	public String getDegree() {
		return degree;
	}

	public void setDegree(String degree) {
		this.degree = degree;
	}

	public String getExperience() {
		return experience;
	}

	public void setExperience(String experience) {
		this.experience = experience;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	/***************************************点评信息***************************/

	public Integer getComID() {
		return comID;
	}

	public void setComID(Integer comID) {
		this.comID = comID;
	}

	public Integer getAppFormID() {
		return AppFormID;
	}

	public void setAppFormID(Integer appFormID) {
		AppFormID = appFormID;
	}

	public Integer getCommOperatorID() {
		return commOperatorID;
	}

	public void setCommOperatorID(Integer commOperatorID) {
		this.commOperatorID = commOperatorID;
	}

	public String getCommOperatorName() {
		return commOperatorName;
	}

	public void setCommOperatorName(String commOperatorName) {
		this.commOperatorName = commOperatorName;
	}

	public Date getCommTime() {
		return commTime;
	}

	public void setCommTime(Date commTime) {
		this.commTime = commTime;
	}

	public String getComMes() {
		return comMes;
	}

	public void setComMes(String comMes) {
		this.comMes = comMes;
	}

}
